﻿using System;
using System.Collections.Generic;
using System.Web;

/// <summary>
/// Possible roles for a user
/// </summary>
public enum GroupUserRole
{
    Reader,
    Writer,
    GroupAdmin,
    Administrator
}

/// <summary>
/// User of a UserGroup
/// </summary>
public class User
{
    #region Properties

    private GroupUserRole _role;
    public GroupUserRole Role
    {
        get { return _role; }
        set { _role = value; }
    }

    private string _id;
    public string Id
    {
        get { return _id; }
        set { _id = value; }
    }
    #endregion

    #region C'tor

    public User(string id, GroupUserRole role)
	{
        if (string.IsNullOrEmpty(id))
            throw new ApplicationException("Invalid user key (empty)");
        Id = id.ToLower();
        Role = role;
    }

    #endregion

}

/// <summary>
/// Group of a UserGroup
/// </summary>
public class Group
{
    #region Properties

    private Dictionary<string, User> _dicoUser;
    public Dictionary<string, User> DicoUser
    {
        get { return _dicoUser; }
    }

    private string _id;
    public string Id
    {
        get { return _id; }
        set { _id = value; }
    }

    #endregion

    #region C'tor

    public Group(string id)
    {
        Id = id;
        _dicoUser = new Dictionary<string, User>();
    }

    #endregion

    #region Public methods

    public void AddUser(User u)
    {
        // Ignore if already present
        if (DicoUser.ContainsKey(u.Id) == false)
            DicoUser.Add(u.Id, u);
    }
    #endregion
}

public class OwnerGroupDico : Dictionary<string, Group>
{
    private Dictionary<string, User> _dicoAdmin;
    public Dictionary<string, User> DicoAdmin
    {
        get { return _dicoAdmin; }
        set { _dicoAdmin = value; }
    }

}
